# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/21'
__author__ = 'Just'
__filename__ = 'theme'
"""
from flask import jsonify
from app.libs.error_code import DeleteSuccess, Success, ParameterException, NotFoundException
from app.libs.redprint import Redprint
from app.libs.token_auth import auth
from app.model.base import db
from app.model.comic import Comic
from app.model.theme import Theme
from app.validators.form import ThemeChangeForm, ThemeDataForm
from app.viewmodel.theme import ThemeViewModel, ThemeCollection


api = Redprint('theme')


@api.route('', methods=['GET'])
def themes():
    """获取主题列表"""
    theme_list = Theme.get_theme_list()
    if not theme_list:
        raise NotFoundException(msg='暂无主题记录数据', error_code=4010)
    comics = [item.comics.all() for item in theme_list]
    collection = ThemeCollection()
    collection.fill(list(zip(theme_list, comics)))
    return jsonify(collection)
